package com.dlmu.MapDemo;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapDemo2 {
    public static void main(String[] args) {
        Map<String,String> map=new HashMap<>();
        map.put("1","1");
        map.put("2","2");
        map.put("3","3");
        map.put("4","4");
        //方法返回set集合，set集合中的元素是键值对对象，因此写成Map.Entey<,>
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String key=entry.getKey();
            String values=entry.getValue();
            System.out.println(key+"="+values);
        }
        System.out.println("迭代器遍历");
        Iterator<Map.Entry<String, String>> iterator = entries.iterator();
        while(iterator.hasNext()){
            Map.Entry<String, String> next = iterator.next();
            String key=next.getKey();
            String values=next.getValue();
            System.out.println(key+"="+values);
        }

    }
}
